<template>
  选择角色：
  <div v-for="(item, key) in role_list" :key="key">
    <input type="checkbox" v-model="selected_role" :value="item.id" :id="item.id" >{{ item.name }}
  </div>
  <el-button type="primary" @click="add_role">确定</el-button>
</template>

<script setup>
  import { ref, onMounted } from "vue"
  import { useRoute, useRouter } from "vue-router";
  import http from "../http"

  const route = useRoute()
  const router = useRouter()

  let id = route.query.id

  let role_list = ref([])

  let selected_role = ref([])

  const add_role = () => {
    http.post(`workflow/create_workflow_role/`, {"workflow_id": id, "role_list": selected_role.value})
    .then(res=>{
      console.log(res)
      router.push({path: '/workflow_examine', query: {'id': id}})
    })
    .catch(error=>{
      console.log(error)
    }
    )
  }

  const getrolelist = () =>{
    http.get(`myadmin/role_list/`)
    .then(res=>{
      console.log(res)
      role_list.value = res.data
    })
    .catch(error=>{
      console.log(error)
    })
  }

  onMounted(() => {
    getrolelist()
  })

</script>
